<%@ page import="com.scfire.project.Project;com.scfire.project.MainCate" %>
<!DOCTYPE html>
<html lang="en">
	<head>
   	<meta name="layout" content="main_mobile">
        <title>火堆</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0 , user-scalable=no">
    
		
		<link rel="stylesheet" href="${resource(dir: 'frozen/css', file: 'frozen.css')}" type="text/css">
		<link rel="stylesheet" href="${resource(dir: 'css', file: 'default.css')}" type="text/css">
		
		<script type="text/javascript" src="${resource(dir: '/frozen/js', file: 'zepto.min.js')}" ></script>
		<script type="text/javascript" src="${resource(dir: '/frozen/js', file: 'frozen.js')}" ></script>
        <script src="${resource(dir: 'js', file: 'util_mobile.js')}" type="text/javascript"></script>         
        <link rel="stylesheet" href="${resource(dir: 'css', file: 'project_launch_2.0.css')}" type="text/css">
        <script type="text/javascript" src="${resource(dir: 'js', file: 'jquery-1.10.2.js')}"></script>
        <script type="text/javascript" src="${resource(dir: 'js', file: 'area.js')}"></script>
        <script type="text/javascript" src="${resource(dir: 'js', file: 'ajaxfileupload.js')}"></script>
	    <style>
		    .form-common input.canNotNull ,.form-common textarea.canNotNull {
		      border-color: #E9666B;
		      outline: 0;
		      -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(233, 102, 127, 0.6);
		      box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(233, 102, 137, 0.6);
		  }
		  div.img-box.canNotNull{
		      -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(233, 102, 127, 0.6)!important;
		      box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(233, 102, 137, 0.6);
		      border: 1px solid #E9666B!important;
		  }
		</style>
    </head>
    
<body>

	
	
	<g:form id = "all-form" url="[resource:projectInstance, action:'save']" method="post" class="ui-form form-common2">
        <div class="step step1">
        <input type= "hidden" name="id" id="id" value="${projectInstance.id}"/>
            <footer class="ui-footer ui-footer-stable ui-border-t">
                <div class="ui-footer-btns">
                    <button type="button" class="btn-save-all btn-footer btn-yellow">保存</button>
                    <button type="button" class="btn-submit-all btn-footer btn-red">提交审核</button>
                </div>
            </footer>

            <section class="ui-container">
                <div class="ui-placehold-img form-img-bg">
                    <input type="file" id="img-p" name="img-p">
                    <input type="hidden" name="projectimg" id="projectimg" value="" >
                    <span id="project-bg" style="display: none; background-image: url(${resource(dir:'images/demo',file:'demo-project-1.jpg')});"></span>
                    <div class="hint">点击可替换图片</div>
                    <div class="btn-add-box">
                        <img src="${resource(dir:'images',file:'btn-camera.png')}" alt="">
                        <p>点击添加封面图片</p>
                    </div>
                </div>

                <div class="u-module">
                    <div class="ui-form-item ui-form-item-show ui-border-tb">
                        <label for="#">标题</label>
                        <input name="name" value="${projectInstance.name}" type="text" placeholder="例: 为山区孩子上一节梦想课" oninput="checkWords(this, 15)" onblur="subWord(this,15)" >
                        <div class="form-unit count">15</div>
                    </div>
                    <div class="ui-form-item ui-form-item-textarea ui-border-b">
                        <label for="#">摘要</label>
                        <textarea name="description"   placeholder="例：每天3元为贫困学童提供免费午餐，让山区孩子远离饥饿的世界。" oninput="checkWords(this, 50)" onblur="subWord(this,50)">${projectInstance.description}</textarea>
                        <div class="form-unit count">50</div>
                    </div>
                </div>

                <div class="u-module">
                    <div class="ui-form-item ui-form-item-show ui-form-item-link ui-border-tb">
                        <label for="#">类型</label>
                        <select name="" id="maincate-select" onchange="mainCate(this)">
                            <option value="" selected disabled>选择类型</option>
                            <option value="100001" >培训活动</option>
                            <option value="100002" >教学物资</option>
                            <option value="100003" >学术创新</option>
                            <option value="100004" >其他</option>
                        </select>
                        <input type="hidden" name="maincate" value="100001" id="maincate"/>
                    </div>
                    
                    <div class="ui-form-item ui-form-item-link ui-border-b">
                        <label for="#">地域</label>
                        <input id="linkStep4" name="address" value="${projectInstance.address}" type="text" placeholder="添加项目执行地点" readonly onclick="goStep(4)">
                    </div>
                    
                    <div class="ui-form-item ui-form-item-link ui-border-b">
                        <label for="#">详情</label>
                        <input id="linkStep2" type="text" value="${projectInstance.detail}" placeholder="用朴实的语言讲述你或他们的故事" readonly onclick="goStep(2);$('.step2 .detail-content').addClass('show')">
                    </div>
                </div>

                <div class="u-module">
                    <div class="ui-form-item ui-form-item-show ui-border-tb">
                        <label for="#">天数</label>
                        <input type="number" name="datanum" value="${projectInstance.donateTimelimit==0?'':projectInstance.donateTimelimit}" placeholder="范围1-99天(提交后不可修改)" onblur="checkInputNum(1, 99, this);">
                        <div class="form-unit">天</div>
                    </div>
                    <div class="ui-form-item ui-form-item-link ui-border-b">
                        <label for="#">清单</label>
                        <input id="linkStep3" type="text" value="${projectInstance.amount==0?'':projectInstance.amount+'元'}" placeholder="添加筹集内容(提交后不可修改)" readonly onclick="goStep(3)">
                    </div>
                </div>
            </section>
        </div>
        
        <!-- step2 详情页 -->
        <div class="step step2">
            <footer class="ui-footer ui-footer-stable ui-border-t">
                <div class="ui-footer-btns">
                    <button type="button" class=" btn-footer btn-red" onclick="compStep2()">完成</button>
                </div>
            </footer>

            <section class="ui-container">
                <div class="header-line">
                    <i class="sf ui-icon-return" onclick="compStep2()"></i>
                    <a href="#"><i>i</i>查看示例</a>
                    <div class="ct">图文详情</div>
                </div>
                <p class="hint ui-border-t">可使用 <b>#小标题内容#</b> 制作个性化小标题<i class="sf u-ic-close" onclick=""></i></p>
                <div class="detail-content ui-border-t show">
                    <textarea id="detail-content" name="detail" placeholder="用朴实的语言讲述你或者他们的故事，让公众理解你发起项目的原因和独特价值。比如，为什么寻求支持/接触到的群体真实需求/你准备做些什么及计划等。" oninput="checkWords(this, 800)" onblur="subWord(this,800)">${projectInstance.detail}</textarea>
                    <div class="form-unit count">800</div>
                    <b class="btn-pull"><img src="../images/btn-pull.png" alt=""></b>
                </div>

                <div class="line">图文描述（限10张）</div>
                <div id='hiddenPic'>
            	</div>
                <div class="form-imgs move" data-index="1">
                    <div class="img-line ui-border-t">
                        <input type="file" id="img-1" name="img-1">
                        
                        <div class="img-box">
                            <img class="move-top" src="${resource(dir:'images',file:'btn-move-top.png')}" alt="">
                            <img class="move-down" src="${resource(dir:'images',file:'btn-move-down.png')}" alt="">
                        </div>
                        <div class="content">
                            <b class="btn-del">&times;</b>
                            <textarea name ="projectpiccontent" id="projectpiccontent1" placeholder="照片描述"></textarea>
                        </div>
                    </div>
                </div>
                <div class="btn-add-img">+上传照片（点击照片排序）</div>
            </section>
        </div>
        
        
         <div class="step step4" style="display: none;">
    	<div class="header-line">
			<i class="sf ui-icon-return" onclick="compStep2()"></i>
			<div class="ct">地域</div>
		</div>
        <div class="u-module">
                <div class="ui-form-item ui-form-item-show ui-form-item-link ui-border-tb">
                <label for="#">地区</label>   
                    <select name="" id="s_province">
                        <option value="0" selected="" disabled="">选择省</option>
                    </select>
                </div>
                <div class="ui-form-item ui-form-item-show ui-form-item-link ui-border-b">
                    <select name="" id="s_city">
                        <option value="0" selected="" disabled="">选择市</option>
                    </select>
                </div>
                 <div class="ui-form-item ui-form-item-show ui-form-item-link ui-border-b" style="display:none">
                    <select name="" id="s_county">
                        <option value="0" selected="" disabled="">选择区县</option>
                    </select>
                </div>
            </div>

        <footer class="ui-footer ui-footer-stable ui-border-t">
            <div class="ui-footer-btns">
                <button type="button" class=" btn-footer btn-red" onclick="compStep4( $('#s_province').val(),$('#s_city').val())">完成</button>
            </div>
        </footer>
    </div>
        
        
        
        <!-- step3 详情页 -->
        <div class="step step3" >
            <footer class="ui-footer ui-footer-stable ui-border-t">
                <div class="ui-footer-btns">
                    <button type="button" class=" btn-footer btn-red" onclick="compStep3()">完成</button>
                </div>
            </footer>
            <div class="header-line">
                    <i class="sf ui-icon-return" onclick="compStep3()"></i>
                    <div class="ct">详细清单</div>
            </div>
			<div id ="fundraise-list" style="display: none">
				<g:each status="i"  in="${projectInstance.fundraises}" var="fundraisevar" >
						<div id="datalist${i+1}">
							<input type="hidden" id="fname${i+1}" name="fundraisename" value='${fundraisevar.name}'>
							<input type="hidden" id="fprice${i+1}" name="fundraiseprice" value='${fundraisevar.price}'>
							<input type="hidden" id="fcount${i+1}" name="fundraisenum" value='${fundraisevar.count}'>
						</div>
				</g:each>
			</div>
            <section class="ui-container">
                <div class="lists">
                    <ul class="ui-row momeny-list head">
                        <li class="ui-col ui-col-50 ui-border-b"><p class="ui-nowrap">品名</p></li>
                        <li class="ui-col ui-col-30 ui-border-b"><p class="ui-nowrap">单价</p></li>
                        <li class="ui-col ui-col-20 ui-border-b"><p class="ui-nowrap">数量</p></li>
                    </ul>
                   
                    <g:each status="i" in="${projectInstance.fundraises}" var="fundraise">
	                     <ul class="ui-row momeny-list ui-arrowlink" indexpoint="${i+1}" id="fundraise-show${i+1}">
			                	<li class="ui-col ui-col-50 ui-border-b"><p class="ui-nowrap">${fundraise.name}</p></li>
				                <li class="ui-col ui-col-30 ui-border-b"><p class="ui-nowrap">${fundraise.price}<i>元</i></p></li>
				                <li class="ui-col ui-col-20 ui-border-b"><p class="ui-nowrap">x${fundraise.count}</p></li>
				          </ul>
		              </g:each>
		              
                </div>
                <div class="btn-add-thing ui-border-b ui-arrowlink">+添加条目</div>
                <div class="total">
                   	 合计 : <span class="price all">${projectInstance.amount}<i>元</i></span>
                </div>

			<div class="new-list-cover">
                    <footer class="ui-footer ui-footer-stable ui-border-t">
                        <div class="ui-footer-btns">
                            <button type="button" class="btn-footer btn-gray btn-del">删除</button>
                            <button type="button" class="btn-footer btn-red btn-save">保存</button>
                        </div>
                    </footer>

                    <div class="new-list">
                        <div class="top">
                            <span class="btn-close"></span>
                            	请确认清单内容
                        </div>

                        <div class="ui-form-item ui-form-item-show ui-border-tb">
                            <label for="#">品名</label>
                            <input id="fundraisename-edit" type="text" placeholder="筹集单项名称，如”篮球“" oninput="checkWords(this,10)" onblur="subWord(this,10)">
                            <div class="form-unit count">10</div>
                        </div>

                        <div class="ui-form-item ui-form-item-show ui-border-b">
                            <label for="#">单价</label>
                            <input id="fundraiseprice-edit" type="number" placeholder="输入单项金额，如5.34" onblur="checkFloatNum(this, 0.0);sum();">
                            <div class="form-unit">元</div>
                        </div>

                        <div class="ui-form-item ui-form-item-show ui-border-b">
                            <label for="#">数量</label>
                            <input id="fundraisenum-edit" type="number" placeholder="范围 1~99999" onblur="checkInputNum(1, 99999, this);sum();">
                        </div>

                        <div class="total">
                            	小计 : <span id="price_sum" class="price">0.00<i>元</i></span>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <input type="hidden" id="save-type" name="saveType" value="${projectInstance?.verified}" >
    </g:form>
	
	
	
	<div class="dialog-step">
        <div class="dialog-box">
            <h4>参考示例</h4>
            <div class="txt">
                	背景描述
					<p>各位亲爱的朋友，你们好！</p>
					<p>我是张智宏，真爱梦想的志愿者。</p>
					<p>今年3月28日, 我发起“拥抱星星的孩子”网络微捐活动，是为新疆的自闭症儿童打造一所梦想中心，为这里的孩子和老师带来新颖的课堂体验和教学技术。</p>
					<p>临近4月2日，这是世界第八个自闭症关注日，我希望此次可以凝聚大家的力量，筹集十万元善款，为新疆自闭症儿童建一所他们自己的乐园。</p>
					图文描述
					<p>#陪伴，是最长情的关爱#</p>
					<p>这些年每次见到这些孩子，他们都有新的进步，都会带给我小小的惊喜。</p>
					<p>我立刻就觉得认识这样一群孩子，是我非常正确的选择。</p>
					<p>2013年，第一次与星星的孩子牵手做游戏。</p>
					<img src="${resource(dir:'images/demo',file:'file0001.jpg')}" alt="">
					<p>2014年，与他们一起制作可爱的手工皂。</p>
					<img src="${resource(dir:'images/demo',file:'file0002.jpg')}" alt="">
					<p>2015年，我想带给孩子们更多地成长，为他们搭建一间梦想中心……</p>
					<p>用你喜欢的姿势，拥抱星星的孩子。</p>
					<p>你的任意一笔善款，都是拥护孩子的力量。我们非常珍惜每一份爱心，无论金额的大小。</p>
					<img src="${resource(dir:'images/demo',file:'file0003.jpg')}" alt="">
					<p>#我们是谁#</p>
					<p>在结识真爱梦想之前，我在新疆经常组织关注自闭症孩子的公益项目。2014年年末，有幸认识了真爱梦想理事长潘江雪，知道了梦想中心、梦想课程，十分认同真爱梦想所提倡的多元、宽容、创新的教育理念。我也意识到，要帮助一群孩子、一个地区、乃至一个社会的发展，教育问题是根源。而我内心的热诚也被点燃了……</p>
					<p>自闭症孩子，以及从事这方面教学工作的老师，也需要不断的改善学习环境、教学理念和方式。</p>
					<p>作为一名新疆的企业家，我希望为家乡建设出一份力量，也希望带动身边更多的朋友参与到这场教育生态圈的共建中。</p>
					<p>与大家合力完成第一个梦想中心的善款募集，这是一个开始！</p>
					<img src="${resource(dir:'images/demo',file:'file0004.jpg')}" alt="">
					<p>#项目执行及善款反馈机构#</p>
					<p>上海真爱梦想公益基金会（2008年在上海市民政局注册成立。致力于中国素质教育发展。中国首家按照上市公司标准披露年报的慈善基金会，凭借标准流程化的项目建设、互联网化的项目运作和以“透明、真实”的上市公司标准进行年报编制和披露，2013年10月30日，真爱梦想连续三年蝉联《福布斯》中文版“中国慈善基金榜”榜首，被誉为“最透明的基金会”）</p>
					<p>开始行动吧！</p>
					<p>让阳光透进紧闭的门，温暖每一个角落!让我们传递爱与温暖，给自闭症儿童撑起一片蓝天。</p>
					<p>关爱星星的孩子，让我们走进他们的心灵世界!</p>
            </div>
            <div class="btn-red btn-close">我知道了</div>
        </div>
    </div>
    
    <div class="ui-dialog" id="save-dialog">
	    <div class="ui-dialog-cnt">
	    	<div class="ui-dialog-bd">
		    	<div>
		    		<h4>保存中</h4>
		    	</div>
	    	</div>
    	</div>
    </div>
    
    <div class="ui-dialog" id="submit-dialog">
    	<div class="ui-dialog-cnt">
    		<div class="ui-dialog-bd">
    			<div>
    			<h4>温馨提示</h4><div>天数与清单项提交审核后不可修改</div>
    			</div>
    		</div>
	    	<div class="ui-dialog-ft ui-btn-group">
	    		<button type="button" data-role="button" class="select" id="dialogButton-submit" onclick="submitAll();">确认</button>
	    		<button type="button" data-role="button" id="dialogButton-cancel" onclick="closeDialog('submit-dialog')">取消</button>
	    	</div>
    	</div>
    </div>

	<div>
	    <g:each in="${projectPics}" var="projectPic" status="i">
	          <input type='hidden' value='${projectPic.content}' id="cPic${i}">
	    </g:each>
    </div>
<script type="text/javascript">
	var fundrasieIndex = ${projectInstance.fundraises.size()};
	var fundrasieCounts = ${projectInstance.fundraises.size()};
	var totalPrice = ${projectInstance.amount};


	var titleStates = true;
	var posterStates =true;
	
	$(function() {
		_init_area();
		//selecter
          $("#maincate-select").val("${projectInstance.mainCate.code}");
          //alert($(cate).html());

          //pics
          <g:each in="${projectPics}" var="projectPic" status="i">
          addImgInfo('${projectPic.pic}', $("#cPic${i}").val());//多行字符串问题
      	</g:each>

          //projectPic
      	var pic = '${projectInstance.img}';
          var imageurl = "/scfire/project/imgRead?img="+pic;	                   
          $("#project-bg").show().css('background-image', 'url(' + imageurl + ')');
          $("#project-bg").siblings('.btn-add-box').hide().siblings('.hint').show().siblings('span').show();
          //图片地址赋值给后台
          $("#projectimg").val('${projectInstance.img}');

          $('.step2 .detail-content .btn-pull').click(function(){
              $(this).parent().toggleClass('show');
          })

          
          $('.form-common2 .ui-placehold-img.form-img-bg').on('change', 'input[type=file]', function(){
            //返回的图片路劲
            var obj = $(this);
            obj.siblings('.btn-add-box').hide().siblings('.hint').show().siblings('span').show();
            var file = obj.attr('id');

            $.ajaxFileUpload({  
        			url:'/scfire/project/imgSaveMb',  
        			secureuri:false,  
        			dataType:'text',
        			fileElementId:file,//file标签的id 
        			success: function (data, status) { 
			           	if(data=='large'){
			           		showWarn('图片过大')
			           		return
			           	}
			       		if(data=='format'){
			           		showWarn('图片格式不对')
			           		return
			           	}
		               //把图片替换  
		               if(data=='fail'){
		               		showWarn('上传失败')
		               }else{
		            	   //图片预览
		                   var imageurl = "/scfire/project/imgRead?img="+data;	                   
		                   $("#project-bg").show().css('background-image', 'url(' + imageurl + ')');
		                   //图片地址赋值给后台
		                   $("#projectimg").val(data);
		                   $("#img-p").replaceWith('<input type="file" id="img-p" name="img-p"/>');                
		               }
		           },  
		           error: function (data, status, e) {  
		           }
		       	 });
        });

        $('.step2 .detail-content textarea').focus(function(){
            $(this).parent().addClass('show');
        })
        $('.step2 .detail-content textarea').blur(function(){
            $(this).parent().removeClass('show');  
        })

        $('.step2 .header-line a').click(function(){
            $('.dialog-step').addClass('show');
        });
        $('.dialog-step .dialog-box .btn-close').click(function(){
           $('.dialog-step').removeClass('show'); 
        });

		
		$('.btn-save').click(function(){
            //
            var name = $("#fundraisename-edit").val();
            if(name == ""){
            	alert("输入正确的品名！");
            	return;
            }
            
            var price = $("#fundraiseprice-edit").val();
            if(price == ""){
            	alert("输入单价！");
            	return;
            }
            
            var count = $("#fundraisenum-edit").val();
            if(count == ""){
            	alert("输入数量！");
            	return;
            }
            
            var subtotal = price * count;
            subtotal = parseFloat(subtotal.toFixed(2));
            if(fundrasieIndex != 0){
            
            	var uHtml = '\
	                        <li class="ui-col ui-col-50 ui-border-b"><p class="ui-nowrap">'+name+'</p></li>\
	                        <li class="ui-col ui-col-30 ui-border-b"><p class="ui-nowrap">'+price+'<i>元</i></p></li>\
	                        <li class="ui-col ui-col-20 ui-border-b"><p class="ui-nowrap">x'+count+'</p></li>\
	                        '
	            $("#fundraise-show"+fundrasieIndex).html(uHtml);
	            
	            totalPrice += (subtotal - (parseFloat($("#fprice"+fundrasieIndex).val())*parseInt($("#fcount"+fundrasieIndex).val())));
	            $(".price.all").html(totalPrice.toFixed(2)+"<i>元</i>");
	            
	            $("#fname"+fundrasieIndex).val(name);
	            $("#fprice"+fundrasieIndex).val(price);
	            $("#fcount"+fundrasieIndex).val(count);

            }
            else{
	            fundrasieCounts ++;
	            var i = fundrasieCounts;
	
	            var nHtml = '<ul class="ui-row momeny-list ui-arrowlink" indexPoint="'+i+'" id="fundraise-show'+i+'">\
	                        <li class="ui-col ui-col-50 ui-border-b"><p class="ui-nowrap">'+name+'</p></li>\
	                        <li class="ui-col ui-col-30 ui-border-b"><p class="ui-nowrap">'+price+'<i>元</i></p></li>\
	                        <li class="ui-col ui-col-20 ui-border-b"><p class="ui-nowrap">x'+count+'</p></li>\
	                        </ul>'
	             var dataList = '<div id="datalist'+i+'"><input type="hidden" id="fname'+i+'" name="fundraisename" value='+name+'>\
								<input type="hidden" id="fprice'+i+'" name="fundraiseprice" value='+price+'>\
								<input type="hidden" id="fcount'+i+'" name="fundraisenum" value='+count+'></div>'
	
				$(".step3 .lists").html($(".step3 .lists").html()+nHtml);
				$("#fundraise-list").html($("#fundraise-list").html()+dataList);
				
				totalPrice =  parseFloat((subtotal+totalPrice).toFixed(2));
				$(".price.all").html(totalPrice.toFixed(2)+"<i>元</i>");
				
				}
				$('.new-list-cover').removeClass('show');
        });
        
        $('.btn-del').click(function(){
            //
            if(fundrasieIndex == 0){
            	$('.new-list-cover').removeClass('show');
            	return;
            }
            else{
            
            	totalPrice -= (parseFloat($("#fprice"+fundrasieIndex).val())*parseInt($("#fcount"+fundrasieIndex).val()));
                $("#datalist"+fundrasieIndex).remove();
                $("#fundraise-show"+fundrasieIndex).remove();
                
                $(".price.all").html(totalPrice.toFixed(2)+"<i>元</i>");
            }
            $('.new-list-cover').removeClass('show');
        });
        
        $('.step3 .btn-add-thing').click(function(){
        	fundrasieIndex = 0;
        	$("#fundraisename-edit").val("");
            $("#fundraiseprice-edit").val("");
            $("#fundraisenum-edit").val("");
            $("#price_sum").html(0.00+"<i>元</i>");
            $('.new-list-cover').addClass('show');
        });
        
        $('.step3 .lists').on('click', '.momeny-list.ui-arrowlink', function(){
            // 需把当前条目数据传入
            fundrasieIndex = $(this).attr("indexPoint");
            //alert(fundrasieIndex);
            $("#fundraisename-edit").val($("#fname"+fundrasieIndex).val());
            $("#fundraiseprice-edit").val($("#fprice"+fundrasieIndex).val());
            $("#fundraisenum-edit").val($("#fcount"+fundrasieIndex).val());
            $('.new-list-cover').addClass('show');
        });
        
        $('.new-list-cover .new-list .top .btn-close').click(function(){
            $('.new-list-cover').removeClass('show');
        });
        

        // 图文相关的操作js
        $('.step2').on('click', '.form-imgs', function(){
            if ($(this).hasClass('move')) {
                $(this).removeClass('move').find('.img-line.move').removeClass('move');
            } 
        });
        $('.step2 .form-imgs').on('click', '.img-line .img-box .move-top', function(e){
        
        	var img = $(this).parents('.img-line').children('.img-box').attr("imgvalue");
            //console.log(img);
            var $inputCur = $("#hiddenPic").children("input[value="+img+"]");
            $inputCur.after($inputCur.prev());
            
            var $cur = $(this).parents('.img-line');
            $cur.after($cur.prev());
            e.stopPropagation();
        });
        $('.step2 .form-imgs').on('click', '.img-line .img-box .move-down', function(e){
        	var img = $(this).parents('.img-line').children('.img-box').attr("imgvalue");
            //console.log(img);
            var $inputCur = $("#hiddenPic").children("input[value="+img+"]");
            $inputCur.before($inputCur.next());
            
            var $cur = $(this).parents('.img-line');
            $cur.before($cur.next());
            e.stopPropagation();
        });
        $('.step2 .form-imgs').on('click', '.img-line .content .btn-del', function(){
        	var img = $(this).parents('.img-line').children('.img-box').attr("imgvalue");
            //console.log(img);
            $(this).parents('.img-line').remove();
            $("#hiddenPic").children("input[value="+img+"]").remove();
            //删除隐藏层 img input
        });
        $('.step2 .form-imgs').on('click', '.img-line .img-box', function(){
            var obj = this;
            setTimeout(function(){
                $(obj).parents('.img-line').addClass('move').parents('.form-imgs').addClass('move');
            }, 10);
            
        });
        $('.step2 .btn-add-img').click(function(){
            $('.step2 .form-imgs > .img-line:last-child input[type=file]').click();
        });
        
        //保存
		$('.btn-save-all').click(function(){
			 if(!checkNull()){
			 	return;
			 }
			 var neixin=$("#save-type").val()
			 if(neixin==""){
			  $("#save-type").val("draft");
			 }
			 $("#save-dialog").addClass('show');
	         setTimeout('$("#all-form").submit()',800);
	    });
	    
	    //提交
	    $('.btn-submit-all').click(function(){
	    	 if(!checkForm()){
	    	 	return;
	    	 }
	    	 if($("#save-type").val()=="draft"){
	    	 $("#save-type").val("modify");
	    	 }
	         $("#submit-dialog").addClass('show');
	    });
        
        
        $('.step2 .form-imgs').on('change', '.img-line input[type=file]', function(){
            // 异步上传图片请求返回的url地址
            $('.step2 .form-imgs').find('.img-line:last-child .img-box').addClass("loading");

            var file = $('.img-line:last-child input[type=file]').attr('id');
            $.ajaxFileUpload({  
        			url:'/scfire/project/imgSaveMb',  
        			secureuri:false,  
        			dataType:'text',
        			fileElementId:file,//file标签的id 
        			success: function (data, status) { 
			           	if(data=='large'){
			           		showWarn('图片过大')
			           		return
			           	}
			       		if(data=='format'){
			           		showWarn('图片格式不对')
			           		return
			           	}
		               //把图片替换  
		               if(data=='fail'){
		               		showWarn('上传失败')
		               }else{
		            	   //图片预览
		                   var imageurl = "/scfire/project/imgRead?img="+data;	                   
		                   addNewImgPreview(imageurl, data);

	                       $("#hiddenPic").html($("#hiddenPic").html()+'<input type="hidden" name="projectpic" value="'+data+'"/>');
		               }
		           },  
		           error: function (data, status, e) {  
		           }
		       	 });
            //var url = '../images/demo/demo-p-1.jpg'; // 本地测试数据
            
        });
        
        if (sessionStorage.getItem('lanuchTitleHide') == null) {
            $('.step2 p.hint').show();
            $('.u-ic-close').click(function(){
            $('.step2 p.hint').hide();
                sessionStorage.setItem('lanuchTitleHide', true);
            });
        } else {
            $('.step2 p.hint').hide();
        }
        
    });


	function addImgInfo(data, context){
		var imageurl = "/scfire/project/imgRead?img="+data;
		
        addNewImgPreview(imageurl, data);
        //图片地址赋值给后台
        $("#hiddenPic").html($("#hiddenPic").html()+'<input type="hidden" name="projectpic" value="'+data+'"/>');
        //图文内容传给后台
        var imgs = $('.form-imgs');
        var index = parseInt(imgs.attr('data-index'))-1;
        $("#projectpiccontent"+index).html(context);
        
		}
	
    function goStep (n) {
        $('.step.step' + n).show().siblings('.step').hide();
    }

    function checkWords (obj, n) {
        var c = 0;
        if ($(obj).val().length > n) {
            c = 0;
        } else {
            c = n - $(obj).val().length;
        }
        $(obj).siblings('.count').text(c);
        
        //
        //$(obj).val($(obj).val().substr(0,n));
        
    }
    
    function subWord(obj, n){
    	if ($(obj).val().length > n) {
            $(obj).val($(obj).val().substr(0,n));
        }
    }

    // input file 的 id 以  img1 img2 img3 …… 以此类推命名
    function addNewImgPreview (url, img) {
        var imgs = $('.step2 .form-imgs');
        imgs.find('.img-line:last-child .img-box').attr("imgvalue", img).removeClass("loading").css('background-image', 'url(' + url + ')').find('input[type=hidden]').val(url);

		var index = parseInt(imgs.attr('data-index'));
        index++;

        var html = '<div class="img-line ui-border-t"><input type="file" id="img-' + index + '" name = "img-'+index+'"><div class="img-box"><img class="move-top" src="../images/btn-move-top.png" alt=""><img class="move-down" src="../images/btn-move-down.png" alt=""></div><div class="content"><b class="btn-del">&times;</b><textarea name="projectpiccontent" id="projectpiccontent'+index+'" placeholder="照片描述"></textarea></div></div>'

        imgs.attr('data-index', index).append(html);
    }

    function compStep2 () {
        $('#linkStep2').val($('.step2 .detail-content textarea').val());
        goStep(1);
    }
    function compStep3 () {
        $('#linkStep3').val($('.step3 .total .price.all').text());
        goStep(1)
    }
    
	function compStep4 (x,y) {
        $('#linkStep4').val(x+' '+y);
        goStep(1)
    }

	function closeDialog(element){
		$("#"+element).removeClass('show');
	}
	function submitAll(){
		$("#all-form").submit();
	}
	
	function checkForm(){
		var projectimg = $("#projectimg").val();
		var name = $("input[name=name]").val();
		var description = $("textarea[name=description]").val();
		var dateNum = $("input[name=datanum]").val();
		var type= $("input[name=mainCate]").val();
		var fundraise = $("#fundraise-list").html();
		var detail = $("input[name=detail]").val();
		var address = $('input[name=address]').val();
		
		
		if(projectimg == ''){
			alert("请上传海报");
			return false;
		}
		if(name == ''){
			alert("请填写项目标题");
			return false;
		}
		if(description == ''){
			alert("请填写项目摘要");
			return false;
		}
		if(type ==''){
			alert("请选择项目类型");
			return false;
		}
		if(address ==''){
			alert("请输入项目发起地");
			return false;
		}
		
		if(dateNum == ''){
			alert("请填写筹集天数");
			return false;
		}
		if(trim(fundraise).length == 0){
			alert("请填写项目清单");
			return false;
		}
		if(detail == ''){
			alert("请填写项目详情");
			return false;
		}
		
		return true;
	}
	
	function trim( text ){
	  if (typeof(text) == "string")
	  {
	    return text.replace(/^\s*|\s*$/g, "");
	  }
	  else
	  {
	    return text;
	  }
	}

    function calFormNum (obj, add) {
        if (typeof add == 'undefined') {
            add = true;
        }
        correctInputNum(obj);
        var c = parseInt($(obj).val());    
        c += (add ? 1 : -1);
        if (c < 1) {
            c = 1;
        } else if (c > 99) {
            c = 99;
        }
        $(obj).val(c);
    }
    
    function correctInputNum (obj) {
        var v = correctNum($(obj).val());
        if (v == '') {
            $(obj).val('1');
        } else {
            $(obj).val(v);
        }
    }
    
    function correctNum (num) {
        return (num + '').replace(/\D/g, '');
    }
    
    
    function checkInputNum(least, most, element){
    	var num = element.value 
        if(!(/^\d+$/.test(num))){
            //alert("输入的数字有误！");
            element.value = least;
        }
        else if(num < least){
        	element.value = least;
        }
        else if(num > most){
        	element.value = most;
        }
    }
    
    function fulldetail(data){
    	$("#detail-content").html(data);
    }
    
    function mainCate(code){
		$("#maincate").val(code.value);
	}
	
	function checkFloatNum(element, init){
    	var num = element.value 
    	if(!(/^\d+(\.\d{1,2})?$/.test(num))){
    		alert("输入正确的价格，最多允许两位小数！");
            element.value = init;
    	}
    }
	
	function sum(){
        var price = $("#fundraiseprice-edit").val();
        var count = $("#fundraisenum-edit").val();
		//console.log(size);
		
		var sum = price *  count;	
		
		$("#price_sum").html(sum.toFixed(2)+"<i>元</i>");
	}
	
	function goLook(){
            window.location.href = "/scfire/user/userCenterDetail?detail=myproject";
    }
    
    function checkNull(){
    
    	var element = $("input[name=name]");
    	var obj = element.val();
    	if(obj == ''){
    		titleStates = false;
    	}
    	else{
    		titleStates = true;
    	}
    	//changeButtonStates();
    	if(!posterStates){
    		alert("请上传海报");
    		//$('.btn-save-all').attr("disabled",false);
    		//$('.btn-submit-all').attr("disabled",false);
    		//$('.btn-save-all').attr("disabled",true);
    		//$('.btn-submit-all').attr("disabled",ture);
    		return false;
    	}
    	if(!titleStates){
    		alert("请填写标题");
    		return false;
    	}
    	return true;
    }
		
	</script>
</body>
</html>